const fs = require('fs')
const path = require('path')
const dataPath = path.resolve(__dirname, './json')
const JSON2Excel = require('./JSON2Excel')

fs.readdir(dataPath ,'utf-8', (err, files) => {
  for(let fileName of files) {
    const filePath = path.join(dataPath, fileName)
    const hashMap = {}
    const JSONData = require(filePath)
    for(let item of JSONData) {
      
      const hash = item['商户名称'] + item['商户地址']
      hashMap[hash] = hashMap[hash] || item
    }



    fs.writeFileSync(filePath, JSON.stringify( Object.values(hashMap)) )
    JSON2Excel(filePath)
  }

})